package cn.iocoder.yudao.module.system.event;

import lombok.Data;
import org.springframework.context.ApplicationEvent;

import java.time.LocalDateTime;

/**
 * 用户活动事件
 * 
 * @author 系统开发团队
 */
@Data
public class UserActivityEvent extends ApplicationEvent {

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户名
     */
    private String username;

    /**
     * 用户类型
     */
    private Integer userType;

    /**
     * 活动类型
     * 1-登录 2-页面访问 3-API调用 4-功能使用
     */
    private Integer activityType;

    /**
     * 活动详情
     */
    private String activityDetail;

    /**
     * 客户端IP
     */
    private String clientIp;

    /**
     * 用户代理
     */
    private String userAgent;

    /**
     * 设备类型
     * 1-PC 2-移动端 3-Web
     */
    private Integer deviceType;

    /**
     * 活动时间
     */
    private LocalDateTime activityTime;

    /**
     * 请求URI
     */
    private String requestUri;

    /**
     * 请求方法
     */
    private String requestMethod;

    /**
     * 会话ID
     */
    private String sessionId;

    public UserActivityEvent(Object source) {
        super(source);
        this.activityTime = LocalDateTime.now();
    }

    public UserActivityEvent(Object source, Long userId, String username, Integer userType, 
                           Integer activityType, String activityDetail) {
        super(source);
        this.userId = userId;
        this.username = username;
        this.userType = userType;
        this.activityType = activityType;
        this.activityDetail = activityDetail;
        this.activityTime = LocalDateTime.now();
    }

    /**
     * 活动类型常量
     */
    public static class ActivityType {
        public static final int LOGIN = 1;
        public static final int PAGE_VIEW = 2;
        public static final int API_CALL = 3;
        public static final int FEATURE_USE = 4;
    }

    /**
     * 设备类型常量
     */
    public static class DeviceType {
        public static final int PC = 1;
        public static final int MOBILE = 2;
        public static final int WEB = 3;
    }
}